package GameOfLife;

/**
 * The Class representing a cell of Game of Life
 */
public class Cell implements Comparable<Cell> {

	/**
	 * a boolean that says if the cell isAlive (true) or not (false)
	 */
	private boolean isAlive;

	/**
	 * a Position Object that will enable us to get the cell position on the
	 * grid
	 */
	private Position position;

	/**
	 * default constructor
	 */
	public Cell() {
	}

	/**
	 * the Cell constructor
	 * 
	 * @param isAlive
	 *            if the cell is alive or not
	 * @param position
	 *            the cell's position
	 */
	public Cell(boolean isAlive, Position position) {
		this.isAlive = isAlive;
		this.position = position;
	}

	/**
	 * <<<<<<< .mine the Living Cell constructor
	 * 
	 * @param isAlive
	 *            if the cell is alive or not
	 * @param position
	 *            the cell's position
	 */
	public Cell(Position position) {
		this.isAlive = true;
		this.position = position;
	}

	/**
	 * ======= equals method to compare if a Cell c is the same as this cell.
	 */
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Cell other = (Cell) obj;
		return this.position.equals(other.getPosition());
	}

	/**
	 * >>>>>>> .r9 getter of the isAlive attribute
	 * 
	 * @return
	 */
	public boolean isAlive() {
		return isAlive;
	}

	/**
	 * setter of the isAlive attribute
	 * 
	 * @param isAlive
	 */
	public void setAlive(boolean isAlive) {
		this.isAlive = isAlive;
	}

	/**
	 * getter of the Position attribute
	 * 
	 * @return
	 */
	public Position getPosition() {
		return position;
	}

	/**
	 * setter of the Position attribute
	 * 
	 * @return
	 */
	public void setPosition(Position position) {
		this.position = position;
	}

	/**
	 * the Cell toString
	 */
	@Override
	public String toString() {
		return "Cell [position=" + position + "]" + "\n";
	}

	@Override
	public int compareTo(Cell o) {
		
		if (this.position.getY() < o.position.getY()) {

			return -1;

		} else if (this.position.getY() == o.position.getY()) {

			if (this.position.getX() < o.position.getX()) {
				return -1;
			} else if (this.position.getX() == o.position.getX()) {
				return 0;
			} else {
				return 1;
			}
			

		} else {

			return 1;

		}
	}


	
}
